/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author ariel
 */
@Entity
@Table(name = "cut_process")
public class CutProcess extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;
    
    
    private Long id;
    private Date initDate;
    private Date endDate;
    private List<AsignationCut> asignationCuts;
    private Employee employee;
    private List<CutDetail> cutDetail;

    private List<PurchaseDetailCutProcess> listPurchaseDetailCutProcess
                                    = new ArrayList<PurchaseDetailCutProcess>();

    private Float totalAmountFail;
    private Float totalAmount;
    private Float totalCurrentAmount;
    private BalanceEmployee balanceEmployee;

    public  CutProcess(){ }

    public  CutProcess(Long i, Date iD, Float tA, Float tAFail, Float tCA, Date eD){
        id = i;
        initDate = iD;
        totalAmount = tA;
        totalAmountFail = tAFail;
        totalCurrentAmount = tCA;
        endDate = eD;
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_cut_process", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "init_date", length = 10)
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "end_date", length = 10)
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cutProcess")
    public List<AsignationCut> getAsignationCuts() {
        return asignationCuts;
    }


    public void setAsignationCuts(List<AsignationCut> asignationCuts) {
        this.asignationCuts = asignationCuts;
    }

    @JoinColumn(name = "id_employee", referencedColumnName = "id_user")
    @ManyToOne(optional = false)
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cutProcess")
    public List<CutDetail> getCutDetail() {
        return cutDetail;
    }

    public void setCutDetail(List<CutDetail> cutDetail) {
        this.cutDetail = cutDetail;
    }

    @Column(name = "total_amount")
    public Float getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Float totalAmount) {
        this.totalAmount = totalAmount;
    }

    @Column(name = "total_amount_fail")
    public Float getTotalAmountFail() {
        return totalAmountFail;
    }

    public void setTotalAmountFail(Float totalAmountFail) {
        this.totalAmountFail = totalAmountFail;
    }

    @Column(name = "total_current_amount")
    public Float getTotalCurrentAmount() {
        return totalCurrentAmount;
    }

    public void setTotalCurrentAmount(Float totalCurrentAmount) {
        this.totalCurrentAmount = totalCurrentAmount;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CutProcess)) {
            return false;
        }
        CutProcess other = (CutProcess) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.CutProcess[id=" + id + "]";
    }

    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "cutProcess")
    public List<PurchaseDetailCutProcess> getListPurchaseDetailCutProcess() {
        return listPurchaseDetailCutProcess;
    }

    public void setListPurchaseDetailCutProcess(List<PurchaseDetailCutProcess> listPurchaseDetailCutProcess) {
        this.listPurchaseDetailCutProcess = listPurchaseDetailCutProcess;
    }

    @OneToOne(mappedBy = "cutProcess")
    public BalanceEmployee getBalanceEmployee() {
        return balanceEmployee;
    }

    public void setBalanceEmployee(BalanceEmployee balanceEmployee) {
        this.balanceEmployee = balanceEmployee;
    }

    @Transient
    public String getDatas(){
        return "init date: "+initDate+" end date: "+endDate+" employee: "+employee.getFullName();
    }
}
